package com.weixin.dao.impl;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import javax.jws.soap.SOAPBinding.Use;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.weixin.dao.StoreDAO;

import com.weixin.entity.Store;

import com.weixin.util.C3p0Util;

public class StoreDAOImpl implements StoreDAO{
	@Override
	public List<Store> getAll() throws SQLException {
		return C3p0Util.qr.query("select * from storehouse_tb where is_show=1 and storehouse_id!=10", new BeanListHandler<Store>(Store.class));
	}

	@Override
	public Store getById(int storehouse_id) throws SQLException {
		return C3p0Util.qr.query("select * from storehouse_tb where storehouse_id=?", new BeanHandler<Store>(Store.class),storehouse_id);
	}
	@Override
	public Store getByName(String storehouse_name) throws SQLException {
		return C3p0Util.qr.query("select * from storehouse_tb where storehouse_name=?", new BeanHandler<Store>(Store.class),storehouse_name);
	}
	@Override
	public boolean insert(Store store) throws SQLException {
		// TODO Auto-generated method stub
		return  C3p0Util.qr.update("insert into storehouse_tb(storehouse_name,creation_date,total_content,residual_content,remark,responsible_person) values(?,?,?,?,?,?)",store.getStorehouse_name(),store.getCreation_date(),store.getTotal_content(),store.getResidual_content(),store.getRemark(),store.getResponsible_person())>0;
	}

	@Override
	public boolean deleteById(int storehouse_id) throws SQLException {
		return C3p0Util.qr.update("update storehouse_tb set is_show=0 where storehouse_id=?",storehouse_id)>0;
	}

	@Override
	public boolean update(Store store) throws SQLException {
		// TODO Auto-generated method stub
		return  C3p0Util.qr.update("update storehouse_tb set storehouse_name=?,creation_date=?,total_content=?,residual_content=?,remark=?,responsible_person=? where storehouse_id=?",store.getStorehouse_name(),store.getCreation_date(),store.getTotal_content(),store.getResidual_content(),store.getRemark(),store.getResponsible_person(),store.getStorehouse_id())>0;
	}

	@Override
	public List<Store> getAllByPage(int pageSize, Integer pageNum) throws SQLException {
		// TODO Auto-generated method stub
		return C3p0Util.qr.query("select * from storehouse_tb where is_show=1 and storehouse_id!=10 limit ?,?", new BeanListHandler<Store>(Store.class),(pageNum-1)*pageSize,pageSize);
	}

	@Override
	public int getTotal() throws SQLException {
		// TODO Auto-generated method stub
		return (int) (long)C3p0Util.qr.query("select count(*) from storehouse_tb where is_show=1 and storehouse_id!=10",new ScalarHandler());
	}
	

	

	
	
	



	

}
